package com.tjetc.service;

import com.tjetc.dao.PlayerDao;
import com.tjetc.domain.Player;
import com.tjetc.utils.Db;
import org.apache.commons.dbutils.QueryRunner;

import java.sql.SQLException;
import java.util.List;

public class PlayerService {
    private PlayerDao playerDao=new PlayerDao();
    public List<Player> showPlayerSalary() {
        try {
            return playerDao. showPlayerSalary();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    public Player findByPlayerName(String playerName) {
        try {
            return playerDao.findByPlayerName(playerName);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public boolean update(int playerid, String playerName1, int playerAge, int playerHeight,int playerWeight, int position, int team_id, int playerSalary, int likes,String playerName) {
        try {
            QueryRunner queryRunner =new QueryRunner();
            Db.start();
            playerDao.update(playerid,playerName1,playerAge,playerHeight,playerWeight,position,team_id,playerSalary,likes,playerName);
            Db.commit();
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            Db.rollback();
        } finally {
            Db.close();
        }

        return false;
    }

    public boolean Likes(String playerName) {
        try {
            QueryRunner queryRunner=new QueryRunner();
            Db.start();
            playerDao.Likes(playerName);
            Db.commit();
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            Db.rollback();
        } finally {
            Db.close();
        }
        return false;
    }

    public Player findByPlayerId(int playerId) {
        try {
            return playerDao.findByPlayerId(playerId);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    public List<Player> findPlayer() {
        try {
            return playerDao.findPlayer();
        } catch (SQLException e) {

        }
        return null;
    }
}
